<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>
    <h1>组合继承</h1>
    <strong>也叫伪经典继承</strong>
    <ul>
      <li>将原型继承和构造函数继承组合在一块</li>
      <li>原型链实现对原型属性和方法的继承</li>
      <li>借用构造函数实现对实例属性的继承</li>
    </ul>
  </div>
  <script>
    function Parent() {
      this.money = 100000
      this.head = 1
      this.hobbies = ['reading', 'fight', 'sleep']
      this.say = function () {
        alert('我喜欢' + this.hobbies)
      }
    }
    // TODO 这和单独使用构造函数实现继承效果一样 所以多敲几行代码有什么意义？
    // Parent.prototype.say = function () {
    //   alert('我是原型方法，通过原型链继承')
    // }

    function Child(name, age) {
      // 将父对象的构造函数绑定在子对象中
      Parent.call(this)
      this.name = name
      this.age = age
    }

    // Child.prototype = new Parent()
    // Child.prototype.constructor = Child
    var son = new Child('jiffy', 22)
    alert(Child.prototype.constructor)
    alert(Parent.prototype.constructor)
    son.say()
  </script>
</body>

</html>